package com.example.springboot.controller;

import lombok.Data;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

@RestController
public class CourseController {

    ArrayList<Course> courseList = new ArrayList<>();
    ArrayList<Course> pendingCourseList = new ArrayList<>();

    @PostMapping("/addCourse")
    @CrossOrigin
    public String addCourse(@RequestBody Course course) {
        pendingCourseList.add(course);
        return "课程已提交待审核";
    }

    @GetMapping("/pendingCourses")
    @CrossOrigin
    public List<Course> getPendingCourses() {
        return pendingCourseList;
    }

    @PostMapping("/approveCourse")
    @CrossOrigin
    public String approveCourse(@RequestBody Course course) {
        pendingCourseList.remove(course);
        courseList.add(course);
        return "课程审核通过";
    }

    @PostMapping("/rejectCourse")
    @CrossOrigin
    public String rejectCourse(@RequestBody Course course) {
        pendingCourseList.remove(course);
        return "课程审核驳回";
    }

    @GetMapping("/courses")
    @CrossOrigin
    public List<Course> getCourses() {
        return courseList;
    }

    // 课程类定义
    @Data
    static class Course {
        static int id;
        public String name;
        public String teacher;
        public String startTime;
        public String endTime;
        public int duration;
        public String description;

        public Course(String name, String teacher, String startTime, String endTime, int duration, String description) {
            id++;
            this.name = name;
            this.teacher = teacher;
            this.startTime = startTime;
            this.endTime = endTime;
            this.duration = duration;
            this.description = description;
        }
    }
}
